package com.EJ.ejcompanyweb.adapter;

import android.os.Bundle;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import com.EJ.ejcompanyweb.entity.ItemEntity;
import com.EJ.ejcompanyweb.fragment.Myfragment;
import java.util.ArrayList;

public class ViewPagerAdapter extends FragmentPagerAdapter {
    private String TAG=this.getClass().getSimpleName();
    private FragmentManager fm;
    private ArrayList<ItemEntity> itemEntities = new ArrayList<ItemEntity>();

    public ViewPagerAdapter(@NonNull FragmentManager fm,ArrayList<ItemEntity> itemEntities) {
        super(fm);
        for (ItemEntity i:itemEntities){
            //拿到 状态栏上的 物资名称和url
            Log.e(TAG,i.toString());
        }
        this.itemEntities=itemEntities;
    }

    @NonNull
    @Override
    public Fragment getItem(int position) {
        Bundle bundle=new Bundle();
        bundle.putString("url",itemEntities.get(position).getUrl());
        bundle.putString("type",itemEntities.get(position).getTitles());
        Myfragment myfragment=new Myfragment();
        myfragment.setArguments(bundle);
        return myfragment;
    }

    @Override
    public int getCount() {
        return itemEntities.size();
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return  itemEntities.get(position).getTitles();
    }

}
